import java.util.Arrays;
import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Gao zhao xu
 * Date: 2023-12-11
 * Time: 上午 09:24
 */
public class Test1 {
    public static int findRoot (int[] root,int[] relation, int x) {
        if (root[x] == x) return x;
        int temp = findRoot(root, relation, root[x]);
        relation[x] = (relation[root[x]] + relation[x]) % 2;
        return temp;
    }
    public static void union (int[] root,int[] relation, int x1, int x2) {
        int x1Root = findRoot(root, relation, x1);
        int x2Root = findRoot(root, relation, x2);
        root[x1Root] = x2Root;
        if (relation[x2] == 0) {
            relation[x1Root] = 1 - relation[x1];
        }else {
            relation[x1Root] = relation[x1];
        }
    }
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        for (int i = 0; i < t; i++) {
            int n = input.nextInt();
            int m = input.nextInt();
            int[] root = new int[n + 1];
            int[] relation = new int[n + 1];
            Arrays.fill(relation, 0);
            for (int j = 0; j <= n; j++) root[j] = j;
            input.nextLine();
            for (int j = 0; j < m; j++) {
                String[] arr = input.nextLine().split(" ");
                int x1 = Integer.parseInt(arr[1]);
                int x2 = Integer.parseInt(arr[2]);
                if (arr[0].equals("A")) {
                    if (findRoot(root,relation, x1) != findRoot(root,relation, x2)) System.out.println("Not sure yet.");
                    else if (relation[x1] != relation[x2]) System.out.println("In different gangs.");
                    else System.out.println("In the same gang.");
                }else if (arr[0].equals("D")) {
                    union(root,relation, x1, x2);
                }
            }
        }
    }
}
